﻿// An example script that demonstrates finding structural PNGs using the Izhikevich search algorithms
// The script creates a new Izhikevich network and matures it with random background firing
// A count of the PNGs in the mature network is then generated both before and after scrambling the network state

#r @"C:\Users\Mira\Source\Repos\Spinula\Debug\SpikingNeuronLib.dll"
#r @"C:\Users\Mira\Source\Repos\Spinula\SpikingAnalyticsBaseLib\bin\Debug\SpikingAnalyticsBaseLib.dll"
#r @"C:\Users\Mira\Source\Repos\Spinula\SpikingAnalyticsLib\bin\Debug\SpikingAnalyticsLib.dll"

open System
open SpikingNeuronLib
open SpikingAnalyticsLib

let outputFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
let algorithmVersion = FindGroupsVersion.Current       // the slower activity-driven PNG search algorithm
let runSeconds = 2 * 3600                               // mature for this many seconds
let backgroundFiringRate = 1                            // with a one hertz random background
let matureNetworkBaseName = "MatureNetwork"
let matureNetworkName = sprintf "%s_%d.txt" matureNetworkBaseName (runSeconds / 60)

// Network definition
let numExcitatoryNeurons = 800
let numInhibitoryNeurons = 200
let numSynapsesPerNeuron = 100
let maxDelay = 20
let networkSpecifier = new IzhikevichNetworkSpecifier(numExcitatoryNeurons, numInhibitoryNeurons, numSynapsesPerNeuron, maxDelay)

// Create a new Izhikevich network
let network = new IzhikevichNetwork(numExcitatoryNeurons, numInhibitoryNeurons, numSynapsesPerNeuron, maxDelay)

// Mature the network and save the network state to a file
PNGScanner.GenerateMaturationStateFiles(network, None, runSeconds, backgroundFiringRate, outputFolder, matureNetworkBaseName)

// Get a count of the PNGs in the network state file
let beforeCount = PNGScanner.FindAllPNGsInStateFile(outputFolder, matureNetworkName, networkSpecifier, "before.txt", algorithmVersion)

// Load the same network state file and scramble the network
let scrambledNetwork = PNGScanner.ScrambleNetworkInStateFile(networkSpecifier, outputFolder, matureNetworkName)

// Get a count of the PNGs in the scrambled network
let afterCount = PNGScanner.FindAllPNGsInState(scrambledNetwork, outputFolder, "after.txt", algorithmVersion)

printfn "%d %d" beforeCount afterCount
